package com.sf.marathon.soul.core.web;

import java.io.IOException;

import org.springframework.http.HttpOutputMessage;
import org.springframework.http.converter.HttpMessageNotWritableException;

import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import com.sf.marathon.soul.core.base.JsonResult;
import com.sf.marathon.soul.core.util.CommonUtils;

/**
 * 返回统一的json格式
 *
 * @author <a href="mailto:tangjimo@sf-express.com">709166</a>
 * @since version1.0 <br>
 * modified by 01368146
 */
public class CustomizeFastJsonHttpMessageConverter extends FastJsonHttpMessageConverter {

    @Override
    protected void writeInternal(Object inputObj, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
        Object value = inputObj;
        if (inputObj != null && !(inputObj instanceof JsonResult)) {
            value = CommonUtils.getDefaultJsonResult(inputObj);
        }
        super.writeInternal(value, outputMessage);
    }
}
